<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    proxy和reflect

    <script>

        function createArray(arr) {
            let handle = {
                get(target, index, receiver) {
                    index = Number(index)
                    if (index < 0) {
                        index += target.length
                    }
                    return Reflect.get(target, index, receiver)
                }
            }
            return new Proxy(arr, handle)
        }

        var arr = [1, 2, 3, 4]

        arr = createArray(arr)
        console.log(arr[-1])


        // var star = {
        //     name: 'zhoujielun',
        //     age: '18',
        //     phoneNumber: '1888888888'

        // }

        // var proxy = new Proxy(star, {
        //     get: function (target, key, receiver) {
        //         if (key === 'phoneNumber') {
        //             return '经纪人电话: 13444445678'
        //         } else {
        //             return Reflect.get(target, key, receiver)
        //         }
        //     }
        // })
        // console.log(proxy.name)
        // console.log(proxy.age)
        // console.log(proxy.phoneNumber)


    </script>

</body>

</html>